package org.grayrabbit.cms.util;

import java.util.ArrayList;
import java.util.List;

import org.grayrabbit.cms.constant.ConstantEnum.TimeFlag;
import org.grayrabbit.cms.vo.search.SearchTime;


public class SearchUtil {
	private  static TimeFlag[] ts= TimeFlag.values();
	
	/**高级查询页  查询范围select
	 * @param list
	 * @return
	 */
	public static List<SearchTime>  loadSearchTimes(List<SearchTime> list){
		baseSearchTimes(list);
		yearsSearchTimes(list);
		SearchTime search = new SearchTime();
		TimeFlag t= ts[ts.length-1];
		search.setKey(t.getKey());
		search.setValue(t.getValue());
		list.add(search);
		return list;
	}
	
	/** 基本查询时间范围
	 * @param list
	 * @return
	 */
	public static List<SearchTime>  baseSearchTimes(List<SearchTime> list){
		if(list == null )  return new ArrayList<SearchTime>();
		SearchTime search= null;
		int i=1;
		for(TimeFlag t: ts){
			i++;
			search = new SearchTime();
			search.setKey(t.getKey());
			search.setValue(t.getValue());
			list.add(search);
			if(i == ts.length)
				break;
		}
		return list;
	}
	
	/** 指定年份查询
	 * @param list
	 * @return
	 */
	public static  List<SearchTime>  yearsSearchTimes(List<SearchTime> list){
		int n = DateUtil.getYearGap();
		SearchTime search= null;
		for(int j=0; j<= n;j++){
			search = new SearchTime();
			search.setKey(DateUtil.START_YEAR + j);
			search.setValue(String.valueOf(DateUtil.START_YEAR + j));
			list.add(search);
		}
		return list;
	}
	
	

}
